<template>
  <j-modal
    switchFullscreen
    :title='title'
    :width='500'
    :visible='visible'
    :maskClosable='false'
    :confirmLoading='confirmLoading'
    @ok='handleOk'
    @cancel='handleCancel'
    cancelText='关闭'>
    <template slot='footer'>
      <a-button @click='handleCancel'>取消</a-button>
      <a-button @click='handleOk' type='primary' v-if='!disableSubmit'>确认</a-button>
    </template>
    <!--    <div class='info-line'>基础设置</div>-->
    <a-spin :spinning='confirmLoading'>
      <a-form :form='form'>
        <a-row :gutter='24'>
          <a-col :md='24' :sm='24'>
            <a-form-item
              :labelCol='labelCol'
              :wrapperCol='wrapperCol'
              label='省'
              >
              <a-input placeholder='请输入' v-decorator="['provinceName', ]"  :disabled='disableSubmit'/>
            </a-form-item>
          </a-col>
          <a-col :md='24' :sm='24'>
            <a-form-item
              :labelCol='labelCol'
              :wrapperCol='wrapperCol'
              label='省编号'
              >
              <a-input placeholder='请输入' v-decorator="['provinceCode', ]" :disabled='disableSubmit'/>
            </a-form-item>
          </a-col>
          <a-col :md='24' :sm='24'>
            <a-form-item
              :labelCol='labelCol'
              :wrapperCol='wrapperCol'
              label='市'
              >
              <a-input placeholder='请输入' v-decorator="['cityName', ]" :disabled='disableSubmit'/>
            </a-form-item>
          </a-col>
          <a-col :md='24' :sm='24'>
            <a-form-item
              :labelCol='labelCol'
              :wrapperCol='wrapperCol'
              label='市编号'
              >
              <a-input placeholder='请输入' v-decorator="['cityCode', ]" :disabled='disableSubmit'/>
            </a-form-item>
          </a-col>
          <a-col :md='24' :sm='24'>
            <a-form-item
              :labelCol='labelCol'
              :wrapperCol='wrapperCol'
              label='区县'
              >
              <a-input placeholder='请输入' v-decorator="['districtName', ]" :disabled='disableSubmit'/>
            </a-form-item>
          </a-col>
          <a-col :md='24' :sm='24'>
            <a-form-item
              :labelCol='labelCol'
              :wrapperCol='wrapperCol'
              label='区县编号'
              >
              <a-input placeholder='请输入' v-decorator="['districtCode', ]" :disabled='disableSubmit' />
            </a-form-item>
          </a-col>
          <a-col :md='24' :sm='24'>
            <a-form-item
              :labelCol='labelCol'
              :wrapperCol='wrapperCol'
              label='街道乡镇'
              >
              <a-input placeholder='请输入' v-decorator="['countryName', ]" :disabled='disableSubmit'/>
            </a-form-item>
          </a-col>
          <a-col :md='24' :sm='24'>
            <a-form-item
              :labelCol='labelCol'
              :wrapperCol='wrapperCol'
              label='街道乡镇编号'
              >
              <a-input placeholder='请输入' v-decorator="['countryCode', ]" :disabled='disableSubmit'/>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>
import proChose from '@comp/cn-components/ProChose'
import { getAction, httpAction, postAction } from '@/api/manage'
import { pick } from 'lodash'
import moment from 'moment'
import JTreeSelect from '@/components/cn-form/JTreeSelect'
import JAreaLinkage from '@comp/cn-form/CnAreaLinkage'
import { isMobile, isPermit } from '@/utils/validate'
import UploadImage from '@/components/upload-image/UploadImage'
import JImageUpload from '@/components/cn-form/JImageUpload'
import Area from '@/components/utils/Area'

export default {
  name: 'politicAreaModal',
  data() {
    return {
      sendPro: false,
      remarks: '',
      dataSurces: [],
      // dataSurces3: [],
      manobjList: [0],
      areaData: '',
      areaLinkage: '',
      title: '操作',
      visible: false,
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 18 }
      },
      confirmLoading: false,
      form: this.$form.createForm(this),
      validatorRules: {
        telephone: {
          rules: [
            { required: true, message: '', trigger: 'submit' },
            {
              validator: function(rule, value, callback) {
                if (!isMobile(value)) {
                  callback(new Error(''))
                }
                callback()
              }
            }
          ]
        },
        businessLicense: {
          rules: [
            { required: true, message: '', trigger: 'submit' },
            {
              validator: function(rule, value, callback) {
                if (!isPermit(value)) {
                  callback(new Error(''))
                }
                callback()
              }
            }
          ]
        },
        terminalName: {
          rules: [
            { required: true, message: '' }
          ]
        },
        warehouseName: {
          rules: [
            { required: true, message: '' }
          ]
        },
        address: {
          rules: [
            { required: true, message: '' }
          ]
        }
      },
      addOrUpdateUrl: window._CONFIG['domianURL'] + '/org/cnRegion/saveOrUpdate'
    }
  },
  components: { JTreeSelect, JAreaLinkage, UploadImage, JImageUpload,proChose },
  created() {
  },
  methods: {
    add() {
      this.edit()
    },
    edit(record) {
      this.form.resetFields()
      this.model = Object.assign({}, record)
      this.visible = true
      this.$nextTick(() => {
        this.form.setFieldsValue(pick(this.model, Object.keys(this.model)))
      })
    },
    close(){
      this.handleCancel()
    },
    handleCancel() {
      this.$emit('close')
      this.visible = false
    },
    // 确定
    handleOk() {
      const that = this
      // 触发表单验证
      this.form.validateFields((err, values) => {
        if (!err) {
          that.confirmLoading = true
          let formData = Object.assign(this.model, values)
          postAction(this.addOrUpdateUrl,formData).then((res) => {
            if (res.success) {
              that.$message.success(res.message)
              that.$emit('ok')
              that.close()
            } else {
              that.$message.warning(res.message)
            }
          }).finally(() => {
            that.confirmLoading = false
          })
        }
      })
    },
  }
}
</script>

<style lang='less' scoped>
.info-line {
  display: flex;
  flex-direction: row;
}

.info-line:before {
  content: "";
  flex: 0.1;
  border-bottom: 1px solid #ebedee;
  margin: auto 4px;
}
.info-line:after {
  content: "";
  flex: 0.9;
  border-bottom: 2px solid #ebedee;
  margin: auto 4px;
}
</style>